home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / vmed.arc / PRINT4.CCC < prev    next >
Encoding:
Text File  |  1985-12-03  |  2.8 KB  |  173 lines

  1. /* PRINT/CCC - General File Printer - March 21, 1983 */
  2. /*    last changed:    November 24, 1983 -- jwk */
  3.  
  4. #include stdio/csh
  5.  
  6. #define PAGSIZ    66
  7. #define MAXTXT    PAGSIZ-6
  8. #define MAXWID    80
  9. #define TABS    4
  10. #option INLIB
  11.  
  12. FILE *fp;
  13. int byte, pgnbr, lnbr, col;
  14.  
  15. main(argc,argv)
  16.     int argc;
  17.     char *argv[];
  18. {
  19.     fprintf(stderr,"%c%c\n",28,31);        /* CLS */
  20.     msg("PRINT4 -- Print File(s)","by page");
  21.     if (argc == 1) {
  22.         dofile(stdin, "");
  23.     }
  24.     else {
  25.         while (--argc) {
  26.             ucs(*++argv);
  27.             if (fp = fopen(*argv,"r")) {
  28.                 dofile(fp, *argv);
  29.                 fclose(fp);
  30.             }
  31.             else
  32.                 msg("CAN'T OPEN",*argv);
  33.         }
  34.     }
  35. }
  36.  
  37. ucs(strng)                /* force STRNG to upper case */
  38.     char *strng;
  39. {
  40.     while (*strng) {
  41.         *strng = toupper(*strng);
  42.         ++strng;
  43.     }
  44. }
  45.  
  46. dofile(file, nptr)                /* process one file */
  47.     FILE *file;
  48.     char *nptr;
  49. {
  50.     msg("Processing file",nptr);
  51.     lnbr=col=0;
  52.     pgnbr=1;
  53.     while (doline(file, nptr));        /* until EOF */
  54.     endpage();                /* flush final page */
  55.     msg("Finished",nptr);
  56. }
  57.  
  58. doline(file, nptr)                /* process one line */
  59.     FILE *file;
  60.     char *nptr;
  61. {
  62.     cktop(nptr);
  63.     while ((byte=getc(file)) != EOF) {
  64.         out(byte);
  65.         if (byte == EOL || byte == 10) {
  66.             ++lnbr;
  67.             col = 0;
  68.             return (TRUE);
  69.         }
  70.     }
  71.     return (FALSE);
  72. }
  73.  
  74. cktop(nptr)                        /* margin control */
  75.     char *nptr;
  76. {
  77. char aray[10];
  78.     if (lnbr > MAXTXT) {    /* at bottom */
  79.         endpage();
  80.     }
  81.     if (lnbr == 0) {        /* at top of a page */
  82.         slew(3);
  83.         putstr(nptr);
  84.         tabto(32);
  85.         time(aray);
  86.         putstr(aray);
  87.         tabto(56);
  88.         date(aray);
  89.         putstr(aray);
  90.         tabto(72);
  91.         putstr("  Page ");
  92.         itoa(pgnbr++,aray);
  93.         putstr(aray);
  94.         slew(3);
  95.     }
  96. }
  97.  
  98. endpage()            /* flush out a full or used page */
  99. {
  100.     if (lnbr) {        /* part of page used anyway */
  101.         while (lnbr++ < PAGSIZ) {
  102.             putchar(' ');
  103.             putchar(EOL);
  104.         }
  105.     lnbr = col = 0;
  106.     }
  107. }
  108.  
  109. out(c)                /* output a byte */
  110.     char c;
  111. {
  112.     if (c == EOL || c == 10) {
  113.         if (!col) putchar(' ');
  114.         putchar(EOL);
  115.         col = 0;
  116.     }
  117.     else {
  118.         if (!col) tabto(8);
  119.         if (c == 9) tabto(col+TABS);
  120.         else {
  121.             putchar(c);
  122.             ++col;
  123.         }
  124.         if (col > MAXWID) {
  125.             if (++lnbr > MAXTXT) endpage();
  126.             else {
  127.                 col = 0;
  128.                 putchar(EOL);
  129.             }
  130.         }
  131.         if (!col) {
  132.             printf("+++++");
  133.             tabto(8);
  134.         }
  135.     }
  136.     if (lnbr > MAXTXT) endpage();
  137. }
  138.  
  139. msg(s1,s2)                        /* message to STDERR */
  140.     char *s1, *s2;
  141. {
  142.     fprintf(stderr,"%s %s\n",s1,s2);
  143. }
  144.  
  145. tabto(n)
  146.     int n;
  147. {
  148.     if (n > MAXWID) n = MAXWID;
  149.     n = n & (-TABS);
  150.     while (col++ < n) putchar(' ');
  151.     --col;
  152. }
  153.  
  154. putstr(strng)            /* send STRNG to STDOUT */
  155.     char *strng;
  156. {
  157.     while (*strng)
  158.         out(*strng++);
  159. }
  160.  
  161. slew(n)                    /* send N EOL's */
  162.     int n;
  163. {
  164.     col = 0;
  165.     while(n-- > 0) {
  166.         out(EOL);
  167.         if (++lnbr >= PAGSIZ) return;
  168.     }
  169. }
  170.  
  171. /*  END OF PROGRAM  */
  172. 
  173.